/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;

using SES.CMS.DAL;
using SES.CMS.DO;
using System.Collections.Generic;
using System.Globalization;
/// <summary>
/// Summary description for CounterBL
/// </summary>
namespace SES.CMS.BL 
{
    public class CounterBL 
    {
    	#region Private Variables
		CounterDAL objCounterDAL;
		#endregion
		
        #region Public Constructors
        public CounterBL()
        {
            //
            // TODO: Add constructor logic here
            //
            objCounterDAL=new CounterDAL();
        }
        #endregion       

        #region Public Methods
        private static int getWeek(DateTime t)
        {
            CultureInfo myCI = new CultureInfo("en-US");
            System.Globalization.Calendar myCal = myCI.Calendar;
            CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;

            DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
            int week = myCal.GetWeekOfYear(t, myCWR, myFirstDOW);
            return week;
        }
        public int Insert(CounterDO objCounterDO)
        {
            return objCounterDAL.Insert(objCounterDO);
        }

        public int Update(CounterDO objCounterDO)
        {
             return objCounterDAL.Update(objCounterDO);

        }

        public int Delete(CounterDO objCounterDO)
        {
             return objCounterDAL.Delete(objCounterDO);

        }

         public int DeleteAll()
        {
             return objCounterDAL.DeleteAll();
        }

        public CounterDO Select(CounterDO objCounterDO)
        {
            return objCounterDAL.Select(objCounterDO);
        }

        public ArrayList SelectAll1( )
        {
         return objCounterDAL.SelectAll1();
        }
        
        public DataTable SelectAll( )
        {
         return objCounterDAL.SelectAll();
        }

        // Trong ngày hôm nay
        public int GetThisDay()
        {
            int i = 0;
            List<CounterDO> lstCounter = objCounterDAL.GetAll();

            foreach (CounterDO item in lstCounter)
            {
                if (item.Date.Date == DateTime.Now.Date)
                    i++;
            }
            return i;
        }
        // Hôm qua
        public int GetYesterday()
        {
            int i = 0;
            List<CounterDO> lstCounter = objCounterDAL.GetAll();

            foreach (CounterDO item in lstCounter)
            {
                if (item.Date.Date == DateTime.Now.Date.AddDays(-1))
                    i++;
            }
            return i;
        }
        // Tuần này
        public int GetCurrentWeek()
        {
            int i = 0;
            List<CounterDO> lstCounter = objCounterDAL.GetAll();

            foreach (CounterDO item in lstCounter)
            {
                if ((item.Date.Year == DateTime.Now.Year) && (getWeek(item.Date)==getWeek(DateTime.Now)))
                    i++;
            }
            return i;
        }
        // Tuần trước
        public int GetPreviousWeek()
        {
            int i = 0;
            List<CounterDO> lstCounter = objCounterDAL.GetAll();

            foreach (CounterDO item in lstCounter)
            {
                if ((item.Date.Year == DateTime.Now.Year) && (getWeek(item.Date) == getWeek(DateTime.Now)-1))
                    i++;
            }
            return i;
        }
        //Tháng này
        public int GetCurrentMonth()
        {
            int i = 0;
            List<CounterDO> lstCounter = objCounterDAL.GetAll();

            foreach (CounterDO item in lstCounter)
            {
                if (item.Date.Month == DateTime.Now.Month)
                    i++;
            }
            return i;
        }
        //Tháng trước
        public int GetPreviousMonth()
        {
            int i = 0;
            List<CounterDO> lstCounter = objCounterDAL.GetAll();

            foreach (CounterDO item in lstCounter)
            {
                if (item.Date.Month == DateTime.Now.Month - 1)
                    i++;
            }
            return i;
        }
        // GetAll
        public int Total()
        {
            return objCounterDAL.GetAll().Count;
        }
#endregion          
    
    
    }

}
